<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@taglib prefix="s" uri="/struts-tags"  %>
<%
	String operation = request.getParameter("operation");
%>
<%@ page import="com.starbaba.core.web.constant.WebConstants"%>
<%@ page import="com.starbaba.system.user.model.UserVO"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
.table>th {
	vertical-align: center;
	background-color: grey;
}
input[type="checkbox"] {
   font-size: 100px;
   vertical-align:middle;
   margin-top:-2px; 
   margin-left:2px;
   margin-bottom:1px;
}
.comment-d {
	border: 1px solid #b5b5b5;margin-bottom: 10px;padding-bottom: 10px;
}
</style>
</head>
<body class="no-skin">
	<div class="page-content">
		<div class="page-content-area">
			<div class="row">
				<div class="col-xs-12 col-sm-12 widget-container-col">
					<form class="form-horizontal" id="product-form"
						name="product-form" method="post" enctype="multipart/form-data">
					<div class="widget-box widget-color-blue">
						<div class="widget-header widget-header-small">
							<h6 class="widget-title lighter">
								<i class="ace-icon glyphicon glyphicon-th-list"></i>活动信息编辑
							</h6>
							<div class="widget-toolbar no-border">
								<a href="#" data-action="collapse"> <i
									class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>

						<div class="widget-body">
							<div class="widget-main" style="padding-bottom: 30px;">
								
									<input type="hidden" name="id" id="id" placeholder=""
										class="col-xs-12 col-sm-6" value="${paramsMap.model.id}">
									<input type="hidden" name="status" id="status" placeholder=""
										class="col-xs-12 col-sm-6" value="${paramsMap.model.status}">
									<input type="hidden" name="operator" value="<%=((UserVO) session.getAttribute(WebConstants.SESSION_ATTRIBUTE_USER)).getUsername() %>"/>
									<div>
										<div>
											<c:if test="${not empty paramsMap.model.id}">
											<label for="from">活动ID</label><br> <input type="text"
												placeholder=""
												readonly
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.id}">
											</c:if>
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">选择模板</label><br>
											<s:select name="modelid" value="%{paramsMap.model.modelid}" list="%{paramsMap.modelList}" listKey="id" listValue="name" cssClass="form-control"></s:select>
										</div>
										<br>
										<div>
										   <label for="from">身份标签：</label><br>
										   <input type="hidden" id="identity_type" name="identity_type" value="${paramsMap.model.identity_type}"/>
										   <input type="checkbox" name="identity_chk_type" value="1">上班族
										   <input type="checkbox" name="identity_chk_type" value="2">学生
										   <input type="checkbox" name="identity_chk_type" value="3">其它
										</div>
										<br>
										<div>
										   <label for="from">现金贷标签：</label><br>
										   <input type="hidden" id="cash_loan_type" name="cash_loan_type" value="${paramsMap.model.cash_loan_type}"/>
										   <input type="checkbox" name="cash_loan_chk_type" value="1">高通过率
										   <input type="checkbox" name="cash_loan_chk_type" value="2">低息好货
										   <input type="checkbox" name="cash_loan_chk_type" value="3">高批额
										</div>
										<br>
										<div>
										   <label for="from">信用卡标签：</label><br>
										   <input type="hidden" id="credit_type" name="credit_type" value="${paramsMap.model.credit_type}"/>
										   <input type="checkbox" name="credit_chk_type" value="1">低息还卡
										   <input type="checkbox" name="credit_chk_type" value="2">极速还卡
										   <input type="checkbox" name="credit_chk_type" value="3">高额度还卡
										</div>
										<br>
										<div>
											<label for="form">利率模式</label><br>
											<input type="radio" id = "dr" name="ratetype" value="1"
											<s:if test="paramsMap.model.ratetype == 1">checked</s:if>>日利率
											<input type="radio" id = "mr" name="ratetype" value="2"
											<s:if test="paramsMap.model.ratetype == 2">checked</s:if>>月利率
										</div>
										<br>
										<div>
											<label for="from">参考利率</label><br> <input type="text"
												name="rate" id="rate" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.rate}">
										</div>
										<br>
										<div>
											<label for="from">跳转链接</label><br> <input type="text"
												name="url" id="url" placeholder=""
												class="col-xs-12 col-sm-12" value="${paramsMap.model.url}">
										</div>
										<br>
										<div>
											<label for="from">活动名称</label><br> <input type="text"
												name="name" id="name" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.name}">
										</div>
										<br>
										<div>
											<label for="from">位置</label><br> <input type="text"
												name="position" id="position"
												placeholder="" class="col-xs-12 col-sm-12"
												value="${paramsMap.model.position}">
										</div>
										<br>
										<div>
											<label for="from">活动描述</label><br> <input type="text"
												name="summary" id="summary"
												placeholder="" class="col-xs-12 col-sm-12"
												value="${paramsMap.model.summary}">
										</div>
										<br>
										<div>
											<label for="from">活动标签(多个,分开)</label><br> <input
												type="text" name="tag" id="tag"
												placeholder="" class="col-xs-12 col-sm-12"
												value="${paramsMap.model.tag}">
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">活动略缩图</label><br> <img id="thumbnail"
												name="thumbnail" src="${paramsMap.model.logo}"
												onerror="javascript:this.src='http://img.xmiles.cn/img/void.png'"
												style="height: 100px;" />
										</div>
										<br>
										<div style="text-align: left">
											<label for="coverimg">(建议图片比例：1:1)</label> <input type="file"
												name="img" class="discovery-input-file" id="img"
												value="${thumbnail}" />
										</div>
										<br>
										<div>
											<label for="from">产品优势(多个,分开)</label><br> <input type="text"
												name="advantage" id="advantage" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.advantage}">
										</div>
										<br>
										<div>
											<label for="from">最低额度(元) </label><br> <input type="text"
												name="minlimit" id="minlimit" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.minlimit}">
										</div>
										<br>
										<div>
											<label for="from">最高额度(元) </label><br> <input type="text"
												name="maxlimit" id="maxlimit" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.maxlimit}">
										</div>
										<br>
										<div>
											<label for="from">预计贷款额度 </label><br> <input type="text"
												name="loanlimit" id="loanlimit" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.loanlimit}">
										</div>
										<br>
										<div>
											<label for="from">初始申请人数 </label><br> <input type="text"
												name="initcount" id="initcount" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.initcount}">
										</div>
										<br>
										<div style="text-align: left">
											<label for="coverimg">批款时间</label> <input type="text"
												name="lenddate" id="lenddate" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.lenddate}">
										</div>
										<br>
										
										<div style="text-align: left">
											<label for="from" id="mint">最短贷款时间(天)
												
											</label>
											<input type="text" name="minterm" id="minterm" placeholder=""
												   class="col-xs-12 col-sm-12"
												   value="${paramsMap.model.minterm }">
										</div>
										<br>
										<div style="text-align: left">
											<label for="from" id="maxt">最长贷款时间(天)
											
											</label>
											<input type="text" name="maxterm" id="maxterm" placeholder=""
												   class="col-xs-12 col-sm-12"
												   value="${paramsMap.model.maxterm }">
										</div>
										<br>
										<div>
											<label for="from">成功申请人数 </label><br> <input type="text"
												name="success_count" id="success_count" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.success_count}">
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">营销标签</label><br> <img id="market_tag"
												name="market_tag" src="${paramsMap.model.market_tag}"
												onerror="javascript:this.src='http://img.xmiles.cn/img/void.png'"
												style="height: 100px;" />
										</div>
										<br>
										<div style="text-align: left">
											<label for="coverimg">(建议图片比例：1:1)</label> <input type="file"
												name="market_img" class="discovery-input-file" id="market_img"
												value="${market_tag}" />
										</div>
										<br>
										<div>
										   <label for="from">API序号</label><br>
										   <input type="text" name="api" id="api"  class="col-xs-12 col-sm-12"
												value="${paramsMap.model.api}">
										</div>

										<div>
										   <label for="from">API模板ID</label><br>
										   <input type="text" name="api_model_id" id="api_model_id"  class="col-xs-12 col-sm-12"
												value="${paramsMap.model.api_model_id}">
										</div>
										<div>
										   <label for="from">联登序号</label><br>
										   <input type="text" name="union_type" id="union_type"  class="col-xs-12 col-sm-12"
												value="${paramsMap.model.union_type}">
										</div>
										<div>
										   <label for="from">联登信息</label><br>
											<select
												name="info_type">
												<option value="0" 
													<s:if test="paramsMap.model.info_type == 0">selected</s:if>>需验证手机号</option>
												<option value="1"
													<s:if test="paramsMap.model.info_type == 1">selected</s:if>>需验证手机号、姓名、身份证</option>
											</select>
										<div>
										   <label for="from">备注</label><br>
										   <textarea rows="3" cols="20" name="remark" id="remark"  class="col-xs-12 col-sm-12" 
										   		>${paramsMap.model.remark}</textarea>
										</div>									
										<div>
										   <label for="from">热度</label><br>
										   <input type="text" name="heat" id="heat"  class="col-xs-12 col-sm-12"
												value="${paramsMap.model.heat}">
										</div>
										<div>
										   <label for="from">放款速度</label><br>
										   <input type="text" name="loan_speed" id="loan_speed"  class="col-xs-12 col-sm-12"
												value="${paramsMap.model.loan_speed}">
										</div>
										<div>
										   <label for="from">通过率</label><br>
										   <input type="text" name="pass_rate" id="pass_rate"  class="col-xs-12 col-sm-12" style="display: inline-block;width:200px;"
												value="${paramsMap.model.pass_rate}"><span style="margin-left:10px;">%</span>
										</div>
									</div>
								
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn  btn-inverse  no-border " onclick="doCancle()"
						id="delete">
						<i class="ace-icon fa fa-undo bigger-160"></i> 取消
					</button>
					&nbsp; &nbsp; &nbsp;
					<button id="btn-save" name="btn-save"
						class="btn  btn-success  no-border" type="button"
						onclick="doSave()">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存
					</button>
				</div>
			</div>
		</div>
	</div>
	<!--模态框-->
	<div class="modal fade" id="Modal">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title"></h4>
				</div>
				<div class="modal-body clearfix">
					<form id="addImage" name="addImage" method="post"
						enctype="multipart/form-data">
						<div class="row">
							<div class="form-group col-xs-12">
								<div class="input-group col-sm-12">
									<input type="file" class="form-control" name="myFile"
										accept=".png,.jpg,.jpeg" />
								</div>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" disabled id="confirm">上传</button>
				</div>
			</div>
		</div>
	</div>

	<%@ include file="/common/common-js.jsp"%>
	<%@ include file="/discovery/maxlength.jsp"%>
	<script type="text/javascript" src="${ctx}/ace/js/maxlength.js"></script>
	<script type="text/javascript" src="${ctx}/js/wangEditor-1.3.11.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script>
		var $multiple = 1;
		var $selector = '';
		var $input = '';

		$(function() {
			$('#img').change(function() {
				var file = this.files[0];
				var r = new FileReader();
				r.readAsDataURL(file);
				$(r).load(function() {
					$('#thumbnail').attr('src', this.result);
					$('#img').attr("value", this.result);
				});
			});
			
			$('#market_img').change(function() {
				var file = this.files[0];
				var r = new FileReader();
				r.readAsDataURL(file);
				$(r).load(function() {
					$('#market_tag').attr('src', this.result);
					$('#market_img').attr("value", this.result);
				});
			});

			//点击按钮
			$('.get-img-modal').on('click', function() {
				//展示模态框
				var $this = $(this);
				var $title = $this.attr('data-title');
				$input = $this.attr('data-input');
				$selector = $this.attr('data-selector');
				$multiple = $this.attr('data-multiple');
				if ($multiple == 1) {
					$('input[name="myFile"]').prop('multiple', true);
				} else {
					$('input[name="myFile"]').prop('multiple', false);
				}
				$('#Modal').find('h4.modal-title').html($title);
				$('#Modal').modal('show');
				return false;
			});

			$('.thumbnail').on('click', function() {
				$('#thumbnail').attr('src', "");
				$("input[id=thumbnail]").val("");
			});

			//上传按钮
			$('#confirm').bind('click', function() {
				if ($('input[name="myFile"]').val() != '') {
					uploadImage('#addImage', $selector, $input, $multiple);
				}
				return false;
			});

			$('input[name="myFile"]').on('change', function() {
				if ($(this).val() != '') {
					$('#confirm').prop('disabled', false);
				} else {
					$('#confirm').prop('disabled', true);
				}
			});
		});
		
		

		$(document).ready(function() {
			if($("#dr").attr("checked")){
				$('#mint').text("最短贷款时间(天)");
		    	$('#maxt').text("最长贷款时间(天)");
			}else{
				$('#mint').text("最短贷款时间(月)");
		    	$('#maxt').text("最长贷款时间(月)");
			}
			//编辑
		    var cash_loan_type = "${paramsMap.model.cash_loan_type}".split(",");
		    for(var i=0; i < cash_loan_type.length;i++){
		    	if(cash_loan_type[i] == 1){
		    		$('input[name="cash_loan_chk_type"][value="1"]').attr("checked",true);
		    	}
		    	if(cash_loan_type[i] == 2){
		    		$('input[name="cash_loan_chk_type"][value="2"]').attr("checked",true);
		    	}
		    	if(cash_loan_type[i] == 3){
		    		$('input[name="cash_loan_chk_type"][value="3"]').attr("checked",true);
		    	}
		    }
		    
		    var identity_type = "${paramsMap.model.identity_type}".split(",");
		    for(var i=0; i < identity_type.length;i++){
		    	if(identity_type[i] == 1){
		    		$('input[name="identity_chk_type"][value="1"]').attr("checked",true);
		    	}
		    	if(identity_type[i] == 2){
		    		$('input[name="identity_chk_type"][value="2"]').attr("checked",true);
		    	}
		    	if(identity_type[i] == 3){
		    		$('input[name="identity_chk_type"][value="3"]').attr("checked",true);
		    	}
		    }
		    
		    var credit_type = "${paramsMap.model.credit_type}".split(",");
		    for(var i=0; i < credit_type.length;i++){
		    	if(credit_type[i] == 1){
		    		$('input[name="credit_chk_type"][value="1"]').attr("checked",true);
		    	}
		    	if(credit_type[i] == 2){
		    		$('input[name="credit_chk_type"][value="2"]').attr("checked",true);
		    	}
		    	if(credit_type[i] == 3){
		    		$('input[name="credit_chk_type"][value="3"]').attr("checked",true);
		    	}
		    }
		});
		
		function uploadImage(form, selector, input, multiple) {
			var options = {
				url : "${ctx}/mall/fileupload/fileUpload.action",
				type : "POST",
				dataType : "json",
				beforeSend : function() {
					$(".load_bg,.load_img").show();
				},
				success : function(data) {
					console.log(data);
					var inputValue = '';
					var dataList = data.split('#');
					insertHtml(dataList, selector, multiple);
					if (multiple == 1) {
						//获取真实input的值
						inputValue = $(input).val();
					}
					
					if (inputValue == '' || inputValue == null) {
						$(input).val(data);
					} else {
						$(input).val(inputValue + '#' + data);
					}

					//隐藏模态框
					$('#Modal').modal('hide');
					//清空modal里面的input的值
					$('input[name="myFile"]').val('');
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert(textStatus);
				},
				complete : function() {
					$(".load_bg,.load_img").hide();
				}
			}
			$('form[name="addImage"]').ajaxSubmit(options);
		}

		function insertHtml(dataList, selector, multiple) {
			var html = '';
			var iconClass = '';
			if (multiple == 0) {
				iconClass = 'change-btntext'
			}
			$.each(dataList, function(index, item) {
				html += '<div class="img-box">' + '<img src="' + item + '"/>'
						+ '<i class="fa fa-times ' + iconClass + '"></i>'
						+ '</div>';
			});
			if (multiple == 1) {
				$(selector).children('.view').removeClass('no-border').append(
						html);
			} else {
				$(selector).children('.view').removeClass('no-border').html(
						html);
			}
		}

		function doCancle() {
			try {
				if (parent) {
					parent.parent['__extdialog_active'].dialog('close');
				}
			} catch (e) {
				window.history.back();
			}
		}

		function doSave() {
			if ($.isBlank($("#name").val())) {
				parent.bootbox.alert("产品名称不能为空!");
				return;
			}
			if ($.isBlank($("#loanlimit").val())) {
				parent.bootbox.alert("预计贷款额度不能为空!");
				return;
			} 
			if ($.isBlank($("#rate").val())) {
				parent.bootbox.alert("利率不能为空!");
				return;
			}
			if(isNaN($("#position").val())){
				parent.bootbox.alert("位置只能为数字");
				return;
			}
			if(isNaN($("#minlimit").val())){
				parent.bootbox.alert("最低额度只能为数字");
				return;
			}
			if(isNaN($("#maxlimit").val())){
				parent.bootbox.alert("最高额度只能为数字");
				return;
			}
			if(isNaN($("#initcount").val())){
				parent.bootbox.alert("初次申请人数只能为数字");
				return;
			}
			if(isNaN($("#minterm").val())){
				parent.bootbox.alert("最短贷款时间只能为数字");
				return;
			}
			if(isNaN($("#maxterm").val())){
				parent.bootbox.alert("最长贷款时间只能为数字");
				return;
			}
			if($("#api").val() != "0" && $("#union_type").val() != "0"){
				if($("#api").val() != "" && $("#union_type").val() != ""){
					parent.bootbox.alert("API序号和联登序号只能任修改一个，默认值为0");
					return;
				}
			}
			
			var minlimit = $("#minlimit")
			
			
		    var identity_chk_value = "";
			$('input[name="identity_chk_type"]:checked').each(function() {
				if ($.isBlank(identity_chk_value)){
				   identity_chk_value += $(this).val();
				} else {
				   identity_chk_value += "," + $(this).val();
				}
			});

			var cash_loan_chk_value = "";
			$('input[name="cash_loan_chk_type"]:checked').each(function() {
				if ($.isBlank(cash_loan_chk_value)){
				   cash_loan_chk_value += $(this).val();
				} else {
				   cash_loan_chk_value += "," + $(this).val();
				}
			});

			var credit_chk_value = "";
			$('input[name="credit_chk_type"]:checked').each(function() {
				if ($.isBlank(credit_chk_value)){
				   credit_chk_value += $(this).val();
				} else {
					credit_chk_value += "," + $(this).val();
				}
			});

			if ($.isBlank(identity_chk_value) && $.isBlank(credit_chk_value) && $.isBlank(cash_loan_chk_value)) {
				parent.bootbox.alert("请选择标签!");
				return;
			}
			$("#identity_type").val(identity_chk_value);
			$("#cash_loan_type").val(cash_loan_chk_value);
			$("#credit_type").val(credit_chk_value);
			
			$("#btn-save").attr("disabled", "disabled");
			saveForm();
		}

		$(function() {
			$("input[name='ratetype']").click(function() {

				var v = $(this).val();

				if (v == "1") {

					$('#mint').text("最短贷款时间(天)");
					$('#maxt').text("最长贷款时间(天)");
				} else {
					$('#mint').text("最短贷款时间(月)");
					$('#maxt').text("最长贷款时间(月)");
				}
			});
		});

		function saveForm() {
			var saveUrl = ctx + "/loanactivity/save.action";
			var options = {
				url : saveUrl,
				type : "POST",
				dataType : "json",
				beforeSend : function() {
					$(".load_bg,.load_img").show();
				},
				success : function(data) {
					alert(data["result"]["msg"]);
					parent.parent['__extdialog_active'].dialog('close');
					parent.query_any();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert(textStatus);
					console.log(XMLHttpRequest, textStatus, errorThrown);
				},
				complete : function() {
					$(".load_bg,.load_img").hide();
				}
			};
			$('form[name="product-form"]').ajaxSubmit(options);
		}

		//日期时间插件
		jQuery(function($) {
			// 注册日历组件
			jQuery(function($) {
				$(".date-picker").datetimepicker({
					autoclose : true,
					format : "yyyy-mm-dd hh:ii:ss"
				}).next().on(ace.click_event, function() {
					$(this).prev().focus();
				});

			});
		});
		
		function isBlock(value){
			if(value == ''|| value==null || value==undefined){
				return true;
			}
			return false;
		}
	</script>
</body>
</html>
